namespace SS.WPF.Framework.ValidationRule
{
    using System.Globalization;
    using System.Windows.Controls;

    /// <summary>
    /// Verify that value should no be null
    /// </summary>
    public class NotNullValidationRule : ValidationRule
    {
        /// <summary>
        /// validate value should no be null
        /// </summary>
        /// <param name="value">
        /// The value will be validate
        /// </param>
        /// <param name="cultureInfo">
        /// The culture info.
        /// </param>
        /// <returns>
        /// ValidationResult indicated the result of the validation
        /// </returns>
        public override ValidationResult Validate(object value, CultureInfo cultureInfo)
        {
            bool result;
            if (value is string)
            {
                result = ((string)value).Trim().Length != 0;
            }
            else
            {
                result = value != null;
            }
            return new ValidationResult(result, "Not null");
        }
    }
}